package dongtai;

public class jiuqiba {
    public static int maxTurbulenceSize(int[] arr) {
        int n=arr.length;
        if(n==1){
            return 1;
        }
        int[] f=new int[n];
        int[] g=new int[n];
        f[0]=g[0]=1;
        // int max=-0x3f3f3f3f;
        int max=1;
        for(int i=1;i<n;i++){
            if(arr[i]>arr[i-1]){
                f[i]=g[i-1]+1;
                 g[i]=1;
            }else if(arr[i]<arr[i-1]){
                 f[i]=1;
                g[i]=f[i-1]+1;
            }else{
                f[i]=g[i]=1;
            }
            max=Math.max(max,Math.max(g[i],f[i]));
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums={4,8,12,16};
        int i = maxTurbulenceSize(nums);
        System.out.println(i);

    }
}
